package com.scau.ums.mapper;

import com.scau.ums.model.Student;
import com.scau.ums.model.Teacher;
import org.apache.ibatis.annotations.*;
import java.util.List;
import java.util.Map;

/**
 * @author xfy
 * @version 1.0
 * @date 2019/8/2 14:07
 */
public interface UserDIYMapper {

    @Update({"update student set password = #{passwordEncoded} WHERE `id` = #{id};"})
    public int resetStudentPasswordById(@Param("id") String id, @Param("passwordEncoded") String passwordEncoded);

    @Update({"update teacher set password = #{passwordEncoded} WHERE `id` = #{id};"})
    public int resetTeacherPasswordById(@Param("id") String id, @Param("passwordEncoded") String passwordEncoded);

    @Update({"update maintainer set password = #{passwordEncoded} WHERE `id` = #{id};"})
    public int resetMaintainerPasswordById(@Param("id") String id, @Param("passwordEncoded") String passwordEncoded);

    @SelectProvider(method = "getStudentNumber",type = com.scau.ums.util.dao.UserSql.class)
    public int getStudentNumber(String searchKeyword);

    @SelectProvider(method = "getStudentListByLimit",type = com.scau.ums.util.dao.UserSql.class)
    public List<Student> getStudentListByLimit(int start, int number, String searchKeyword);

    @SelectProvider(method = "getTeacherNumber",type = com.scau.ums.util.dao.UserSql.class)
    public int getTeacherNumber(String searchKeyword);

    @SelectProvider(method = "getTeacherListByLimit",type = com.scau.ums.util.dao.UserSql.class)
    public List<Teacher> getTeacherListByLimit(int start, int number, String searchKeyword);

    @SelectProvider(method = "getMaintainerNumber", type = com.scau.ums.util.dao.UserSql.class)
    public int getMaintainerNumber(String searchKeyword);

//    //占位符如果类型是string类型的话也不需要加引号
//    @Select(" select count(*) from maintainer, maintainRole, maintainGroup WHERE " +
//            "(maintainer.maintainerGroup=maintainGroup.id  and role=maintainRole.id) and concat(IFNULL(maintainer.id,''),IFNULL(maintainer.name,'')" +
//            ",IFNULL(sex,''),IFNULL(telephone,''),IFNULL(mail,''),IFNULL(maintainGroup.name,''),IFNULL(maintainRole.name,'')) like #{searchKeyword} ")
//    public int getMaintainerNumber(@Param("searchKeyword") String searchKeyword);

    @SelectProvider(method = "getMaintainerListByLimit", type = com.scau.ums.util.dao.UserSql.class)
    public List<Map<String, Object>> getMaintainerListByLimit(int start, int number, String searchKeyword);

//    @Select(" select maintainer.id as id,maintainer.name as name,password,sex,telephone,mail,maintainGroup.name " +
//            "as groups,maintainRole.name as role from maintainer, maintainRole, maintainGroup WHERE " +
//            "(maintainer.maintainerGroup=maintainGroup.id  and role=maintainRole.id) and concat(IFNULL(maintainer.id,''),IFNULL(maintainer.name,'')" +
//            ",IFNULL(sex,''),IFNULL(telephone,''),IFNULL(mail,''),IFNULL(maintainGroup.name,''),IFNULL(maintainRole.name,'')) like #{searchKeyword} " +
//            " limit #{start},#{number};")
//    public List<Map<String, Object>> getMaintainerListByLimit(@Param("start") int start, @Param("number") int number, @Param("searchKeyword") String searchKeyword);

}
